<template>
  <div class="login-page">
    <!-- <a-row> -->
    <!-- <a-col :span="12" class="aside">
        <div class="aside-inner">
          <img src="/images/login.png" />
        </div>
      </a-col> -->
    <!-- <a-col :span="12" class="login-aside"></a-col> -->
    <!-- </a-row> -->
    <a-form class="login-page-form" :label-col="{ span: 4 }" :model="form" :wrapper-col="{ span: 20 }" :rules="rule">
      <h1>广告图设计系统</h1>
      <p class="subTitle"></p>
      <a-form-item label="手机号" required name="cellphone" v-bind="validateInfos.cellphone">
        <a-input placeholder="手机号码" v-model:value="form.cellphone">
          <template v-slot:prefix>
            <UserOutlined style="color:rgba(0,0,0,.25)" />
          </template>
        </a-input>
      </a-form-item>
      <a-form-item placeholder="请输入密码" label="密码" name="password" required v-model:value="form.password">
        <a-input-password v-model:value="form.password">
          <template #prefix>
            <LockOutlined class="site-form-item-icon" />
          </template>
        </a-input-password>
      </a-form-item>
      <a-form-item>
        <a-button type="primary" @click="login">登录</a-button>
      </a-form-item>
    </a-form>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'
// import { useForm } from '@ant-design-vue/use'
import { Form } from 'ant-design-vue';
import { user } from "@/stores/user";
import { message } from 'ant-design-vue';
import { useRouter } from 'vue-router';
const useForm = Form.useForm;
const form = reactive({
  cellphone: '',
  password: ''
})
const rule = reactive({
  cellphone: [
    { required: true, message: '请输入手机号', trigger: 'change' },
  ],
  password: [
    { required: true, message: '验证码不能为空', trigger: 'blur' }
  ]
})
const userStore = user()
const router = useRouter()
const { validate, validateInfos } = useForm(form, rule)
const login = () => {
  validate().then(() => {
    message.success('登录成功 2秒后跳转首页')
    userStore.fetchCurrentUser()
    setTimeout(() => {
      router.push('/')
    }, 2000);
    // console.log('提交表单：', form)
  }).catch((error) => {
    console.log('验证失败：', error)
  })
}
</script>

<style lang="less" scoped>
.login-page {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;

  .login-page-form {
    width: 400px;
    text-align: center;
  }
}

.aside {
  height: 80vh;

  .aside-inner {
    width: 100%;
    height: 100%;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
}
</style>
